package com.edu.exam.enums.common;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 存储状态枚举
 *
 * 通用的存储状态管理，可用于各种临时存储、缓存、备份等场景
 *
 * @author System
 * @version 1.0.0
 */
public enum StorageStatus implements BaseEnum {

    /**
     * 活跃
     */
    ACTIVE("ACTIVE", "活跃"),

    /**
     * 锁定
     */
    LOCKED("LOCKED", "锁定"),

    /**
     * 待处理
     */
    PENDING("PENDING", "待处理"),

    /**
     * 处理中
     */
    PROCESSING("PROCESSING", "处理中"),

    /**
     * 已完成
     */
    COMPLETED("COMPLETED", "已完成"),

    /**
     * 失败
     */
    FAILED("FAILED", "失败"),

    /**
     * 已过期
     */
    EXPIRED("EXPIRED", "已过期"),

    /**
     * 已删除
     */
    DELETED("DELETED", "已删除");

    private final String code;
    private final String description;

    StorageStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public static StorageStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("StorageStatus code cannot be null or empty");
        }
        for (StorageStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown StorageStatus code: " + code);
    }

    public static StorageStatus fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("StorageStatus description cannot be null or empty");
        }
        for (StorageStatus status : values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown StorageStatus description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}